package com.ruoyi.web.controller.api.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.egdk.api.entity.MedicalCapture;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.report.Patient;
import com.ruoyi.system.domain.report.vo.DICOMSeriesImgVo;
import com.ruoyi.system.domain.report.vo.SeriesVo;
import com.ruoyi.system.mapper.report.PatientMapper;
import com.ruoyi.system.service.report.ITeacherService;
import com.ruoyi.web.controller.api.service.ApiServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/api/tspet/")
public class ApiController {

    @Autowired
    private ITeacherService iTeacherService;

    /**
     * 前端查询序列
     *
     * @param studyInsta
     * @return
     */
    @GetMapping("/getStudyInsta/{studyInsta}")
    public AjaxResult getStudyInsta(@PathVariable String studyInsta) {
        List<DICOMSeriesImgVo> seriesVos = iTeacherService.getStudyInsta(studyInsta);
        return AjaxResult.success(seriesVos);
    }

    /**
     * 将用户选择的序列传给后端,后端进行数据逻辑处理
     *
     * @param seriesVo
     * @return
     */
    @PostMapping("/openseries")
    public AjaxResult series(@RequestBody SeriesVo seriesVo) {
        apiService.series(seriesVo);
        return AjaxResult.success();
    }

    @Autowired
    private ApiServiceImpl apiService;

    /**
     * 融合软件发送请求，根据accessToken，查询上面处理好的数据
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/open/{accessToken}")
    public AjaxResult getInfo(@PathVariable String accessToken) {
        JSONObject object = apiService.getInfo(accessToken);
        return AjaxResult.success(object);
    }

    /**
     * 融合软件发送请求，根据accessToken，查询ini文件数据
     *
     * @param accessToken
     * @return
     */
    @GetMapping("/getIni/{accessToken}")
    public AjaxResult getIni(@PathVariable String accessToken) {
        String content = apiService.getIni(accessToken);
        return AjaxResult.success(content);
    }



    /**
     * 根据uuid下载dcm文件
     */
    @GetMapping("/downloadDcm")
    public void downloadDcm(@RequestParam("uuid") String uuid, HttpServletResponse response) {
        apiService.downloadDcm(uuid,response);
    }

    /**
     * 融合软件上传图片
     * */
    @PostMapping("/capture")
    public AjaxResult capture(@RequestBody MedicalCapture capture) {
        System.out.println("capture方法已被执行");
        apiService.handleImageCaptute(capture);
        return AjaxResult.success();
    }


    @GetMapping("/images")
    public AjaxResult getImages(@RequestParam("StudyInsta")String studyInsta){
        return apiService.getImage(studyInsta);
    }




}
